<?php

return [
    'module' => [
        'name' => 'order_refund',
        'title' => '订单退款',
        'table' => 'order_refunds',
    ],
    
    'fields' => [
        'id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '退款记录ID',
            'unsigned' => true,
            'nullable' => false,
            'primary' => true,
            'auto_increment' => true,
            'required' => true,
        ],
        'order_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '订单ID',
            'unsigned' => true,
            'nullable' => false,
            'required' => true,
            'index' => true,
        ],
        'user_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '用户ID',
            'unsigned' => true,
            'nullable' => false,
            'required' => true,
            'index' => true,
        ],
        'refund_no' => [
            'type' => 'varchar',
            'length' => 64,
            'comment' => '退款编号',
            'nullable' => false,
            'required' => true,
            'index' => true,
        ],
        'refund_amount' => [
            'type' => 'decimal',
            'length' => '10,2',
            'comment' => '退款金额',
            'nullable' => false,
            'required' => true,
            'default' => 0.00,
        ],
        'refund_reason' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '退款原因',
            'nullable' => false,
            'required' => true,
        ],
        'refund_evidence' => [
            'type' => 'json',
            'comment' => '退款凭证图片',
            'nullable' => false,
            'required' => true,
        ],
        'status' => [
            'type' => 'tinyint',
            'length' => 4,
            'comment' => '退款状态：0待处理，1已同意，2已拒绝，3退款中，4退款成功，5退款失败',
            'nullable' => false,
            'required' => true,
            'default' => 0,
            'index' => true,
        ],
        'refuse_reason' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '拒绝原因',
            'nullable' => false,
            'default' => '',
        ],
        'refund_time' => [
            'type' => 'timestamp',
            'comment' => '退款时间',
            'nullable' => true,
        ],
        'refund_trade_no' => [
            'type' => 'varchar',
            'length' => 64,
            'comment' => '退款交易号',
            'nullable' => false,
            'default' => '',
        ],
        'admin_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '处理人ID',
            'unsigned' => true,
            'nullable' => false,
            'default' => 0,
        ],
        'created_at' => [
            'type' => 'timestamp',
            'comment' => '创建时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
        ],
        'updated_at' => [
            'type' => 'timestamp',
            'comment' => '更新时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
            'extra' => 'ON UPDATE CURRENT_TIMESTAMP',
        ],
    ],
    
    'relations' => [
        'order' => [
            'type' => 'belongsTo',
            'model' => 'Order',
            'foreign_key' => 'order_id',
        ],
        'user' => [
            'type' => 'belongsTo',
            'model' => 'User',
            'foreign_key' => 'user_id',
        ],
        'admin' => [
            'type' => 'belongsTo',
            'model' => 'Admin',
            'foreign_key' => 'admin_id',
        ],
    ],
    
    'queries' => [
        'order_id' => ['=', '?'],
        'user_id' => ['=', '?'],
        'refund_no' => ['like', '%?%'],
        'status' => ['=', '?'],
        'admin_id' => ['=', '?'],
        'created_at' => ['between', '?,?'],
        'refund_time' => ['between', '?,?'],
    ],
]; 